layui.use(['fileManager', 'upload'], function () {
    let util = layui.util, $ = layui.jquery;
    let upload = layui.upload;
    let fileManager = layui.fileManager, layer = layui.layer;
    let element = layui.element;
    // 初始化upload组件
    let uploadListIns = upload.render({
        elem: '#upload', // 绑定元素
        url: __basePath + '/gen/user/upload', // 上传接口
        accept: 'file', // 允许上传的文件类型
        multiple: true, // 允许多文件上传
        data: {
            pid: function () {
                return $('#selectId').val();
            }
        },
        auto: false, // 选择文件后不自动上传，需要手动点击上传
        bindAction: '#uploadAction', // 指向一个按钮触发上传
        choose: function (obj) {
            var that = this;
            var files = this.files = obj.pushFile(); // 将每次选择的文件追加到文件队列

            // 读取本地文件
            obj.preview(function (index, file, result) {
                var tr = $(['<tr id="upload-' + index + '">',
                    '<td>' + file.name + '</td>',
                    '<td>' + (file.size / 1024).toFixed(2) + 'kb</td>',
                    '<td><div class="layui-progress" lay-filter="progress-demo-' + index + '"><div class="layui-progress-bar" lay-percent=""></div></div></td>',
                    '<td>等待上传</td>',
                    '<td>',
                    '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>',
                    '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>',
                    '</td>',
                    '</tr>'].join(''));

                // 单个重传
                tr.find('.demo-reload').on('click', function () {
                    obj.upload(index, file);
                });

                // 删除
                tr.find('.demo-delete').on('click', function () {
                    delete files[index]; // 删除对应的文件
                    tr.remove();
                    uploadListIns.config.elem.next()[0].value = ''; // 清空 input file 值，以免删除后出现同名文件不可选
                });

                $('#demoList').append(tr);
                element.render('progress'); // 渲染新加的进度条组件
            });
        },
        done: function (res, index, upload) {
            if (res.code > 0) { // 上传成功
                var tr = $('#demoList').find('tr#upload-' + index),
                    tds = tr.children();
                tds.eq(3).html('<span style="color: #5FB878;">上传成功</span>');
                tds.eq(4).html(''); // 清空操作
                $('#demoList').attr("refresh", "1");
                return delete this.files[index]; // 删除文件队列已经上传成功的文件
            }
            this.error(index, upload, res);
        },
        error: function (index, upload, res) {
            console.log(res);
            var tr = $('#demoList').find('tr#upload-' + index),
                tds = tr.children();
            tds.eq(3).html('<span style="color: #FF5722;">' + res.msg + '</span>');
            tds.eq(4).find('.demo-reload').removeClass('layui-hide'); // 显示重传
            element.progress('progress-demo-' + index, 0 + '%'); // 执行进度条。n 即为返回的进度百分比
        },
        progress: function (n, elem, e, index) { // 注意：index 参数为 layui 2.6.6 新增
            element.progress('progress-demo-' + index, n + '%'); // 执行进度条。n 即为返回的进度百分比
        }
    });
    util.on({
        btnSearch: function () {
            fileManagerSearch()
        },
        updatePwd: function () {
            layer.open({
                type: 2,
                title: '修改密码',
                shadeClose: true,
                maxmin: false, //开启最大化最小化按钮
                area: ['600px', '300px'],
                content: __basePath + '/user/pwd'
            });
        },
        logout: function () {

            layer.confirm('是否退出登录？', {
                btn: ['确定', '关闭'], //按钮,
                icon: 3,
                title: "提示"
            }, function () {
                // 跳转到指定的 URL
                window.location.href = __basePath + '/logout';
            }, function () {

            });
        },
        uploads: function () {
            layer.open({
                type: 1,
                area: ['800px', '500px'],
                title: "文件选择",
                shade: true, // 不显示遮罩
                content: $('#upload-layer'), // 捕获的元素
                end: function () {
                    //判断是否需要刷新
                    let r = $('#demoList').attr("refresh");
                    if (r === "1") {
                        fileManagerReload();
                        $('#demoList').attr("refresh", "0");
                    }
                }
            });
        },
        addFolder: function () {
            layer.prompt({title: '文件夹名字', formType: 0}, function (name, index) {
                // 假设我们要在 nodeId 为 '1' 的节点下添加一个子节点
                var nodeId = treeMenu.getSelectId(); // 目标节点的 ID
                post(__basePath + "/gen/user/addFolder", {pid: nodeId, name: name}, function (result) {
                    if (result.code === 1) {
                        layer.close(index);
                        let data = result.data
                        console.log(data)
                        // 查找父节点
                        const parentNode = treeMenu.findNode(nodeId, treeMenu.treeData);
                        if (parentNode) {
                            if (parentNode.children) {
                                treeMenu.addNode(nodeId, data.id, name, data.createTime, data.modifyTime)
                            } else {
                                parentNode.expanded = true;
                                parentNode.loaded = false;
                                parentNode.last = false;
                                treeMenu.render()
                            }
                        }
                        fileManagerReload()
                        successMsg(result.msg)
                        resetInfo()

                    }
                })

            });
        },
        updateName: function () {
            let mode = fileManager.getSelect()
            let id = mode.id
            layer.prompt({title: '重命名', formType: 0, value: mode.name}, function (name, index) {
                // 假设我们要在 nodeId 为 '1' 的节点下添加一个子节点
                post(__basePath + "/gen/user/updateFileName", {_id: id, name: name, pid: mode.pid}, function (result) {
                    if (result.code === 1) {
                        layer.close(index);
                        if (mode.type === 'dir') treeMenu.editNode(id, name, result.data.modifyTime)
                        fileManagerReload()
                        successMsg(result.msg)
                        resetInfo()
                    }

                })


            });
        },
        deleteFile: function () {
            layer.confirm('确定要删除文件吗，删除后不可恢复？', {icon: 3, title: '提示'}, function (index) {
                let ids = fileManager.getSelectIds()
                let dirs = fileManager.getSelectDir()
                layer.close(index);
                post(__basePath + "/gen/user/folder/delete", {ids: ids}, function (result) {
                    if (result.code === 1) {
                        fileManagerReload()
                        successMsg(result.msg)
                        resetInfo()
                        $.each(dirs, function (index, id) {
                            treeMenu.deleteNode(id)
                        });
                    }

                })
            });
        },
        downFile: function () {
            let ids = fileManager.getSelectIds();
            // 创建隐藏的a标签
            let pid = $("#selectId").val();
            if (ids) {
                const link = document.createElement('a');
                link.href = __basePath + "downloadFile?ids=" + ids;
                // 设置文件名（如果提供）
                if (name) {
                    link.download = name;
                }
                // 设置为隐藏元素
                link.style.display = 'none';
                // 添加到页面
                document.body.appendChild(link);
                // 模拟点击
                link.click();
                // 移除元素
                document.body.removeChild(link);
                // $.ajax({
                //     url:__basePath+"/downloadZip",
                //     type: "post",
                //     data:{ids:ids}
                // });
                // $("#idsFiles").val(ids)
                // // 获取表单对象
                // const $form = $('#myDownForm');
                // // 验证通过，提交表单
                // $form.submit();
            }


        }
    });

    function resetInfo() {
        let nodeId = $('#selectId').val()
        const node = treeMenu.findNode(nodeId, treeMenu.treeData);
        $("#file-size").hide();
        $("#file-type").hide();
        $("#dir-select").show();
        $("#fileName").text(node.name);
        $("#fileCreateTime").text(node.createTime);
        $("#fileModifyTime").text(node.modifyTime);
        isDisabled("#btnUpdateName", true)
        isDisabled("#btnDelete", true)
        isDisabled("#btnDown", true)
    }

// 树节点类
    class TreeNode {
        constructor(id, name, parentId, createTime, modifyTime, children = []) {
            this.id = id;
            this.name = name;
            this.children = children;
            this.expanded = false;
            this.loaded = false;
            this.last = false;//是否还有下一级
            this.selected = false; // 新增选中状态
            this.parentId = parentId;
            this.createTime = createTime;
            this.modifyTime = modifyTime;
        }
    }

// 树形菜单类
    class TreeMenu {
        constructor(containerId) {
            this.container = document.getElementById(containerId);
            this.treeData = [];
            this.myMap = new Map();
            this.breadcrumbMap = new Map();
            this.selectedNode = null; // 当前选中的节点
            this.loadPostTree();
        }

        loadPostTree() {
            let treeMenu = this;
            // 打开一个加载层
            var loadIndex = layer.msg('加载中', {
                time: 0, // 90s 后自动关闭
                icon: 16, shade: 0.5
            });

            $.post(__basePath + "/gen/user/folderTree", {parentId: null}, function (data) {
                layer.close(loadIndex)
                if (data.code > 0) {
                    treeMenu.treeData = data.data
                    treeMenu.render();
                    treeMenu.setupEventListeners();
                }
            }, "json");
        }

        // 渲染树
        render() {
            this.container.innerHTML = '';
            this.treeData.forEach(node => this.renderNode(node, this.container));
        }

        // 渲染节点
        renderNode(node, parentElement) {
            const li = document.createElement('li');
            li.className = 'tree-node';
            li.dataset.id = node.id;
            li.dataset.parentId = node.parentId;
            const nodeContent = document.createElement('div');
            nodeContent.className = `node-content ${node.selected ? 'selected' : ''}`;

            const toggleIcon = document.createElement('div');
            toggleIcon.className = 'toggle-icon';
            let children = [];
            if (node.children) children = node.children
            if (node.last) {
                toggleIcon.innerHTML = node.expanded ?
                    '<i class="iconfont-arrow">&#xe730;</i>' :
                    '<i class="iconfont-arrow">&#xe509;</i>';
            }
            // 添加文件夹图标
            const folderIcon = document.createElement('div');
            folderIcon.className = 'folder-icon';
            folderIcon.innerHTML = node.expanded && (children.length > 0) ?
                '<i class="iconfont-folder">&#xe6a3;</i>' :
                '<i class="iconfont-folder">&#xe80c;</i>';

            const label = document.createElement('div');
            label.className = 'node-label';
            label.textContent = node.name;

            nodeContent.appendChild(toggleIcon);
            nodeContent.appendChild(folderIcon);
            nodeContent.appendChild(label);

            li.appendChild(nodeContent);

            const childrenContainer = document.createElement('ul');
            childrenContainer.className = 'children';
            if (node.expanded) {
                childrenContainer.style.display = 'block';

                if (children.length > 0) {
                    children.forEach(child => this.renderNode(child, childrenContainer));
                } else if (!node.loaded) {
                    // 显示加载中
                    const loading = document.createElement('div');
                    loading.className = 'loading';
                    loading.innerHTML = '<div class="spinner"></div> 加载中...';
                    childrenContainer.appendChild(loading);
                    // 模拟异步加载
                    this.loadChildren(node, childrenContainer);
                }
            }

            li.appendChild(childrenContainer);
            parentElement.appendChild(li);
            treeMenu.myMap.set(node.id, node)
            // 设置展开状态类
            if (node.expanded) {
                li.classList.add('expanded');
                if (!this.getSelectId()) {
                    treeMenu.setBreadcrumb(node.id);
                    this.setSelectId(node.id);
                }
            }

        }

        // 模拟异步加载子节点
        loadChildren(node, container) {
            $.post(__basePath + "/gen/user/pid/folder", {pId: node.id}, function (data) {
                if (data.code > 0) {
                    const newChildren = data.data
                    node.children = newChildren;
                    node.loaded = true;
                    // 移除加载指示器
                    container.innerHTML = '';
                    // 渲染新节点
                    newChildren.forEach(child => treeMenu.renderNode(child, container));
                }
            }, "json");


        }

        // 添加节点
        addNode(parentId, id, name, createTime, modifyTime) {
            const newNode = new TreeNode(id, name, parentId, createTime, modifyTime);
            if (!parentId) {
                // 添加根节点
                this.treeData.push(newNode);
            } else {
                // 查找父节点
                const parentNode = this.findNode(parentId, this.treeData);
                if (parentNode) {
                    if (!parentNode.children) {
                        parentNode.children = []
                    }
                    parentNode.children.push(newNode);
                    // 自动展开父节点
                    if (!parentNode.expanded) {
                        parentNode.expanded = true;
                        parentNode.loaded = false;
                        parentNode.last = true;
                    }
                }
            }
            this.render();
        }

        // 编辑节点
        editNode(nodeId, newName, modifyTime) {
            const node = this.findNode(nodeId, this.treeData);
            if (node) {
                node.name = newName;
                node.modifyTime = modifyTime;
                this.render();
            }
        }

        // 删除节点
        deleteNode(nodeId) {
            const deleteRecursive = (nodes, id) => {
                for (let i = 0; i < nodes.length; i++) {
                    if (nodes[i].id === id) {
                        // 如果删除的是选中的节点，清除选中状态
                        if (this.selectedNode && this.selectedNode.id === id) {
                            this.selectedNode = null;
                        }
                        nodes.splice(i, 1);
                        return true;
                    }

                    if (nodes[i].children && nodes[i].children.length > 0) {
                        if (deleteRecursive(nodes[i].children, id)) {
                            return true;
                        }
                    }
                }
                return false;
            };

            deleteRecursive(this.treeData, nodeId);
            if (treeMenu.myMap.has(nodeId)) treeMenu.myMap.delete(2);
            this.render();
        }

        // 查找节点
        findNode(id, nodes) {
            for (const node of nodes) {
                if (node.id === id) {
                    return node;
                }

                if (node.children && node.children.length > 0) {
                    const found = this.findNode(id, node.children);
                    if (found) return found;
                }
            }
            return null;
        }

        // 切换节点展开状态
        toggleNode(nodeId) {
            const node = this.findNode(nodeId, this.treeData);

            if (node) {
                node.expanded = !node.expanded;
                this.render();
            }
        }

        // 展开所有节点
        expandAll() {
            const expand = (nodes) => {
                nodes.forEach(node => {
                    node.expanded = true;
                    if (node.children && node.children.length > 0) {
                        expand(node.children);
                    }
                });
            };

            expand(this.treeData);
            this.render();
        }

        // 折叠所有节点
        collapseAll() {
            const collapse = (nodes) => {
                nodes.forEach(node => {
                    node.expanded = false;
                    if (node.children && node.children.length > 0) {
                        collapse(node.children);
                    }
                });
            };

            collapse(this.treeData);
            this.render();
        }

        // 选中节点
        selectNode(nodeId) {
            // 清除之前选中的节点
            this.clearSelection(this.treeData);
            // 设置新选中的节点
            const node = this.findNode(nodeId, this.treeData);
            if (node) {
                node.selected = true;
                this.selectedNode = node;
                this.render();
            }
        }

        // 清除所有节点的选中状态
        clearSelection(nodes) {
            nodes.forEach(node => {
                node.selected = false;
                if (node.children && node.children.length > 0) {
                    this.clearSelection(node.children);
                }
            });
        }


        // 获取所有节点（扁平化）
        getAllNodes() {
            const nodes = [];

            const traverse = (nodeList) => {
                nodeList.forEach(node => {
                    nodes.push(node);
                    if (node.children && node.children.length > 0) {
                        traverse(node.children);
                    }
                });
            };

            traverse(this.treeData);
            return nodes;
        }

        // 设置事件监听器
        setupEventListeners() {
            // 节点点击事件
            this.container.addEventListener('click', (e) => {
                const target = e.target;
                const nodeElement = target.closest('.tree-node');
                if (!nodeElement) return;

                const nodeId = nodeElement.dataset.id;
                // 切换图标点击
                if (target.closest('.toggle-icon')) {
                    this.toggleNode(nodeId);
                    return;
                }
                // 节点标签点击 - 选中节点
                if (target.closest('.node-label') ||
                    target.closest('.node-content') ||
                    target.closest('.folder-icon')) {
                    this.selectNode(nodeId);
                    treeMenu.setBreadcrumb(nodeId);
                    this.setSelectId(nodeId);
                }
            });
        }

        setSelectId(nodeId) {
            $("#selectId").val(nodeId)
            fileManagerReload()
        }

        getSelectId() {
            return $("#selectId").val()
        }

        setBreadcrumb(nodeId) {
            this.breadcrumbMap.clear();
            this.findNote(nodeId)
            const reversedEntries = [...this.breadcrumbMap.entries()].reverse();
            this.breadcrumbMap.clear();
            reversedEntries.forEach(([key, node]) => {
                this.breadcrumbMap.set(key, node);
            });
            this.showBreadcrumb();
        }

        showBreadcrumb() {
            var breadcrumb = $("#breadcrumb");
            breadcrumb.empty();
            const reversedEntries = [...this.breadcrumbMap.entries()];
            var i = 1;
            let nodeId = "";
            // 倒序遍历
            reversedEntries.forEach(([key, node]) => {
                var html = "";
                const arrow = i < reversedEntries.length ? "breadcrumb-arrow" : ""
                html += '<li class="breadcrumb-item ' + arrow + '" data-id="' + key + '" data-level="' + i + '">' +
                    '<a href="#"><i class="iconfont-folder">&#xe6a3;</i> ' + node + '</a></li>';
                var newItem = $(html); // 创建新的列表项
                if (i === reversedEntries.length) {
                    nodeId = key;
                }
                // 为新添加的列表项添加点击事件
                newItem.on('click', function () {
                    let li = $(this);
                    let plevel = li.attr('data-level');
                    let cl = (li.siblings("li").length + 1).toString();
                    if (cl !== plevel) {
                        console.log(plevel + "----------------" + cl);
                        let pid = li.attr('data-id');
                        breadcrumb.children().each(function () {
                            var li = $(this).attr('data-id');
                            var level = $(this).attr('data-level');
                            if (level > plevel) {
                                treeMenu.breadcrumbMap.delete(li)
                            }
                        });
                        treeMenu.setSelectId(pid);
                        treeMenu.showBreadcrumb();
                    }
                });
                breadcrumb.append(newItem);
                i++;
            });
            const node = this.findNode(nodeId, this.treeData);
            if (node) {
                if (node.name === "位置") {
                    $("#dir-select").hide();
                    $("#fileInfo").addClass("layui-hide");
                } else {
                    $("#dir-select").show();
                    $("#fileName").text(node.name);
                    $("#fileCreateTime").text(node.createTime);
                    $("#fileModifyTime").text(node.modifyTime);
                    $("#fileResolution").hide();
                    $("#file-size").hide();
                    $("#file-type").hide();
                    $("#fileInfo").removeClass("layui-hide");
                }
            }

            isDisabled("#btnAddDir", reversedEntries.length === 1);
            isDisabled("#btnUploadFile", reversedEntries.length === 1);
            hideBtn();
            $('#demoList').attr("refresh", "0");
            $('#demoList').empty();
        }

        findNote(nodeId) {
            if (this.myMap.has(nodeId)) {
                const node = this.myMap.get(nodeId)
                this.breadcrumbMap.set(nodeId, node.name);
                if (node.parentId) {
                    this.findNote(node.parentId);
                }

            }
        }
    }

    function isDisabled(id, disabled) {
        let b = $(id);
        if (disabled) {
            b.addClass("layui-btn-disabled");
            b.attr("disabled");
        } else {
            b.removeClass("layui-btn-disabled");
            b.removeAttr("disabled");
        }

    }

// 初始化树形菜单
    let treeMenu = new TreeMenu('treeMenu');

    fileManager.render({
        elem: '#fileManager',
        method: 'post',
        id: 'fileManager',
        btn_upload: true,
        btn_create: true,
        isDown: isdown,
        icon_url: __basePath + '/assets/ico/',
        url: __basePath + '/gen/user/images',
        thumb: {'nopic': __basePath + '/assets/ico/null-56x56.jpg', 'width': 80, 'height': 80},
        where: {
            pid: $('#selectId').val()
        },
        parseData: function (res) {
            /*
            data:[{
                thumb:文件地址用于显示
                ,type:文件类型  directory文件夹,png|gif|png|image图片,其它任意
                ,path:文件夹路径用于打开本文件夹
            }]
            */
            let _res = [];
            _res.code = 0;
            _res.data = res.data;
            _res.count = res.count
            return _res;
        }
        ,
        done: function (res, curr, count) {
            // console.log(res,curr,count)
        }
        ,
        page: {
            limit: 100,
            curr: 1, // 重新从第 1 页开始
            limits: [100, 200, 500, 1000, 2000, 5000],
            layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
        }
    });

    //监听图片选择事件
    fileManager.on('click(test)', function (obj) {
        //obj.obj 当前对象
        //obj.data 当前图片数据
        let n = fileManager.getCheckNumber()
        if (n === 1) {
            if (obj.data.goId) {
                isDisabled("#btnUpdateName", true)
            } else {
                isDisabled("#btnUpdateName", false)
            }

            var data = obj.data;
            $("#fileName").text(data.name);
            if (data.type === "dir") {
                $("#file-size").hide();
                $("#file-type").hide();
                $("#dir-select").show();
            } else {
                $("#dir-select").hide();
                $("#file-size").show();
                $("#file-type").show();
                $("#fileSize").text(data.fileSizeName + '(' + data.fileSize + 'Byte)');
                $("#fileType").text(data.fileExt);
            }

            $("#fileCreateTime").text(data.createTime);
            $("#fileModifyTime").text(data.modifyTime);

            if (data.resolutionTitle) {
                $("#fileResolutionTitle").text(data.resolutionTitle);
                $("#fileResolutionContent").text(data.resolution);
                $("#fileResolution").show();
            } else {
                $("#fileResolution").hide();
            }
            $("#fileInfo").removeClass("layui-hide");
            $("#multiple-lay").addClass("layui-hide");
        } else {
            $("#dir-select").hide();
            isDisabled("#btnUpdateName", true)
            $("#fileInfo").addClass("layui-hide");
            if (n > 1) {
                $("#multiple-number").text('已选择( ' + n + '项 )');
                $("#multiple-lay").removeClass("layui-hide");
            } else {
                $("#multiple-lay").addClass("layui-hide");
            }
        }
        if (n > 0) {
            if (obj.data.goId) {
                isDisabled("#btnDelete", true)
            } else {
                isDisabled("#btnDelete", false)
            }
            isDisabled("#btnDown", false)
        } else {
            isDisabled("#btnDelete", true)
            isDisabled("#btnDown", true)
        }

    });
    fileManager.on('dblclick(test)', function (obj) {
        //obj.obj 当前对象
        //obj.data 当前图片数据
        var data = obj.data;
        if (data.type === 'dir') {
            treeMenu.breadcrumbMap.set(data.id, data.name);
            treeMenu.setSelectId(data.id);
            treeMenu.showBreadcrumb();
        } else {
            layer.open({
                type: 2,
                title: data.name,
                shadeClose: true,
                maxmin: true, //开启最大化最小化按钮
                area: ['1200px', '700px'],
                content: data.ypath,
            });
        }
    });

    function hideBtn() {
        isDisabled("#btnUpdateName", true)
        isDisabled("#btnDelete", true)
        isDisabled("#btnDown", true)
    }

    function fileManagerSearch() {
        fileManager.reload("fileManager", {
            elem: '#fileManager',
            method: 'post',
            id: 'fileManager',
            btn_upload: true,
            btn_create: true,
            isDown: isdown,
            icon_url: __basePath + '/assets/ico/',
            url: __basePath + '/gen/user/search/images',
            thumb: {'nopic': __basePath + '/assets/ico/null-56x56.jpg', 'width': 80, 'height': 80},
            where: {
                keyword: $('#keyword').val()
            },
            parseData: function (res) {
                let _res = [];
                _res.code = 0;
                _res.data = res.data;
                _res.count = res.count
                return _res;
            }
            ,
            done: function (res, curr, count) {
                // console.log(res,curr,count)
            }
            ,
            page: {
                limit: 100,
                curr: 1, // 重新从第 1 页开始
                limits: [100, 200, 500, 1000, 2000, 5000],
                layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            }
        });
    }

    function fileManagerReload() {
        fileManager.reload("fileManager", {
            elem: '#fileManager',
            method: 'post',
            id: 'fileManager',
            btn_upload: true,
            btn_create: true,
            icon_url: __basePath + '/assets/ico/',
            url: __basePath + '/gen/user/images',
            thumb: {'nopic': __basePath + '/assets/ico/null-56x56.jpg', 'width': 80, 'height': 80},
            where: {
                pid: $('#selectId').val()
            },
            parseData: function (res) {
                let _res = [];
                _res.code = 0;
                _res.data = res.data;
                _res.count = res.count
                return _res;
            }
            ,
            done: function (res, curr, count) {
                // console.log(res,curr,count)
            }
            ,
            page: {
                limit: 100,
                curr: 1, // 重新从第 1 页开始
                limits: [100, 200, 500, 1000, 2000, 5000],
                layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            }
        });
    }

    var laypage = layui.laypage;
    // 完整显示
    laypage.render({
        elem: 'demo-laypage-all', // 元素 id
        count: 100, // 数据总数
        layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
        jump: function (obj) {
        }
    });
    $("#dir-select").hide();
});


function reloadModule(moduleId) {
    let iframe = window.frames[moduleId];
    if (iframe) {
        if (iframe.contentWindow) {
            // 现在你可以访问iframe中的window对象了
            var iframeWindow = iframe.contentWindow;
            // 调用iframe中的方法，例如一个叫做showMessage的方法
            iframeWindow.reloadTable();
        } else if (iframe.contentDocument) {
            // 对于不支持contentWindow的浏览器（例如IE）
            var iframeDocument = iframe.contentDocument;
            var iframeWindow = iframeDocument.defaultView;
            // 调用iframe中的方法
            iframeWindow.reloadTable();
        }
    }
}
